﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System.Collections.Generic;
using System.Windows.Input;
using AForge.Imaging.Filters;
using BrainTechLLC;
using BrainTechLLC.FilterExtensions;
using ImageAppViewModels;

namespace WpfImageDuplicates
{
    public partial class FilterCollectionMakeCopyCommand : RoutedCommand, ICommand
    {
        public void Execute(FilterCollectionCollectionViewModel vm, string oldName)
        {
            var found = vm.FindByName(oldName);

            if (found == null)
            {
                return;
            }

            var old = found;
            var newCollection = new FilterCollection();

            for (int n = 2; n < 1000; n++)
            {
                newCollection.CollectionName = oldName + " (" + n.ToString() + ")";
                found = vm.FindByName(newCollection.CollectionName);

                if (found == null)
                    break;
            }

            for (int n = 0; n < old.Count; n++)
            {
                var fvm = old[n];
                SingleFilter sf = fvm.Filter as SingleFilter;

                if (sf != null)
                {
                    IFilter filter = sf.Filter.MakeCopy(2, 0) as IFilter;

                    var singleFilter = new SingleFilter(filter)
                    {
                        Status = fvm.Status,
                        FilterTypeName = sf.FilterTypeName,
                        FilterType = sf.FilterType
                    };

                    newCollection.AddFilter(singleFilter);
                }
            }

            vm.AddFilterCollection(newCollection);
        }
    }

    public partial class FilterCollectionAddCommand : RoutedCommand, ICommand
    {
        public void Execute(FilterCollectionCollectionViewModel vm, string newName)
        {
            var found = vm.FindByName(newName);

            if (found != null)
            {
                return;
            }

            vm.AddFilterCollection(new FilterCollection() { CollectionName = newName });
        }
    }

    public partial class FilterCollectionRenameCommand : RoutedCommand, ICommand
    {
        public void Execute(FilterCollectionCollectionViewModel vm, string oldName, string newName)
        {
            var found = vm.FindByName(oldName);

            if (found == null)
            {
                return;
            }

            found.CollectionName = newName;
            vm.FilterCollectionNames = null;
        }
    }

    public partial class FilterCollectionRemoveCommand : RoutedCommand, ICommand
    {
        public void Execute(FilterCollectionCollectionViewModel vm, string selectedName)
        {
            var found = vm.FindByName(selectedName);

            if (found == null)
            {
                return;
            }

            vm.RemoveFilterCollection(found);
        }
    }

    public partial class RemoveFilterCommand : RoutedCommand, ICommand
    {
    }

    public partial class RemoveSelectedFiltersCommand : RoutedCommand, ICommand
    {
        public void Execute(FilterCollectionViewModel vm, List<FilterViewModel> toDelete)
        {
            vm.RemoveFilters(toDelete);
        }
    }

    public partial class FilterSettingsCommand : RoutedCommand, ICommand
    {
        public void Execute(FileImageViewModel vm)
        {
        }
    }
}
